<template>
  <div class="exmall">
    <div class="exmall-header">
      <van-swipe :loop="false" :autoplay="1113000" class="swipe-exmall">
        <van-swipe-item v-for="(image, index) in swipes" :key="index">
          <van-image :src="image" />
        </van-swipe-item>
      </van-swipe>
      <div class="flexbox">
        <div
          class="flexbox-item"
          v-for="(cate,cid) in categories"
          :key="cid"
          @click="pushWeblink(cate.link)"
        >
          <van-image :src="cate.thumb" />
          <label>{{cate.title}}</label>
        </div>
      </div>
    </div>

    <div class="spread-box clearfix">
      <div class="square-block" v-for="(item,sid) in spread" :key="sid">
        <div class="square-block-dummy"></div>
        <div class="square-block-box">
          <van-image :src="item.thumb" />
          <div class="spread-item">
            <h3>{{item.title}}</h3>
            <p>{{item.description}}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 活动专区 -->
    <div class="goods-panel" v-if="actgoods.length>0">
      <van-cell-group>
        <van-cell value="更多" icon="shop" :border="false" is-link center>
          <template slot="title">
            <span class="van-cell-text">活动专区</span>
          </template>
        </van-cell>
      </van-cell-group>

      <van-row v-if="actgoods.length >= 3" class="goods-list">
        <van-col span="8" v-for="(o, index) in 3" :key="index">
          <van-card
            :thumb="actgoods[index].thumb"
            class="vertical-card"
            v-on:click.native="pushWeblink(actgoods[index].link)"
          >
            <div slot="tags" class="goods-info">
              <h3 class="van-ellipsis">{{actgoods[index].name}}</h3>
              <p>
                <span class="goods-price">{{actgoods[index].price}}</span>元
              </p>
            </div>
          </van-card>
        </van-col>
      </van-row>
    </div>

    <!-- 推荐 -->
    <div class="goods-panel" v-if="recommends.length>0">
      <van-cell-group>
        <van-cell value="更多" icon="shop" :border="false" is-link center>
          <template slot="title">
            <span class="van-cell-text">为您推荐</span>
          </template>
        </van-cell>
      </van-cell-group>

      <van-row v-if="recommends.length >= 3" class="goods-list">
        <van-col span="8" v-for="(o, index) in 3" :key="index">
          <van-card
            :thumb="recommends[index].thumb"
            class="vertical-card"
            v-on:click.native="pushWeblink(actgoods[index].link)"
          >
            <div slot="tags" class="goods-info">
              <h3 class="van-ellipsis">{{recommends[index].name}}</h3>
              <p>
                <span class="goods-price">{{recommends[index].price}}</span>元
              </p>
            </div>
          </van-card>
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
import { Row, Col, Cell, CellGroup, Swipe, SwipeItem, Card, Image } from 'vant'

export default {
  components: {
    [Row.name]: Row,
    [Col.name]: Col,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [Card.name]: Card,
    [Image.name]: Image
  },

  data () {
    return {
      categories: [],
      swipes: [],
      actgoods: [],
      recommends: [],
      spread: [],
      currentDate: '--'
    }
  },

  created: function () {
    this.axios
      .get('/exmall')
      .then(response => {
        this.swipes = response.data.carousels
        this.categories = response.data.categories
        this.actgoods = response.data.actgoods
        this.recommends = response.data.recommends
        this.spread = response.data.spread
      })
      .catch(function (error) {
        console.log(error)
      })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.spread-box {
  margin: 10px 0;
  .spread-item {
    position: absolute;
    width: 100%;
    height: 100%;
    padding: 10px;
    left: 0;
    top: 0;
    h3 {
      margin: 0;
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      color: #555;
      font-weight: normal;
    }
    p {
      margin: 0;
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      color: #888;
    }
  }
  .square-block {
    float: left;
    margin: 0;
    width: 50%;
    border: 0;
    &-dummy {
      margin-top: 40%;
    }
    &-box {
      background: #fff;
      justify-content: flex-end;
      & img {
        align-self: flex-end;
        width: auto;
      }
    }
    &:first-child {
      .square-block-dummy {
        margin-top: 80%;
      }
      .square-block-box::before {
        position: absolute;
        right: 0;
        top: 0;
        width: 1px;
        height: 100%;
        content: "";
        background: #f5f5f5;
        border-right: 1px solid #f5f5f5;
      }
      .spread-item img {
        height: 50%;
      }
    }
    &:last-child {
      .square-block-box {
        &::before {
          position: absolute;
          left: 0;
          top: -0.5px;
          width: 100%;
          height: 1px;
          content: "";
          background: #f5f5f5;
          border-right: 1px solid #f5f5f5;
        }
      }
    }
  }
}

.exmall-header {
  background: white;
}

.flexbox-item {
  padding: 10px;
  img {
    width: 50%;
  }
  label {
    padding: 5px 0 0;
    display: block;
    font-size: 10px;
    color: #aaa;
  }
}

.user-avatar {
  display: inline-block;
  position: relative;
  vertical-align: middle;
  height: 0.75rem;
  margin-right: 0.2rem;
}

.user-avatar > img {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
}

.user-avatar > span {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 0.2rem;
  height: 0.2rem;
  border-radius: 50%;
  background-color: #ff6600;
  color: #fff;
  line-height: 0.2rem;
  font-size: 0.1rem;
  text-align: center;
}

.swipe-exmall {
  img {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    position: absolute;
    left: 0;
    bottom: 0;
  }
}
.van-swipe-item /deep/ {
  position: relative;
  height: 150px !important;
}

.goods-panel {
  background: white;
  margin-top: 10px;
  /deep/ .van-cell__value span {
    font-size: 85%;
    color: #999;
    vertical-align: middle;
  }
  .goods-list {
    padding: 15px 8px;
  }
}

/deep/ .van-cell__right-icon {
  color: #ccc;
  margin-left: 0;
}
.vertical-card {
  padding: 0 8px;
  display: block;
  height: auto;
  background: transparent;
}
.vertical-card /deep/ .van-card__thumb {
  display: block;
  position: initial;
  width: 100%;
  height: auto;
  img {
    border-radius: 5px;
  }
}

.goods-info {
  padding: 3px 0;
  > h3 {
    margin: 3px 0;
    font-size: 14px;
    color: #666;
  }
  > p {
    margin: 0;
    font-size: 10px;
    font-weight: normal;
    color: #666;
    .goods-price {
      color: #ff7220;
      padding-right: 2px;
    }
  }
}
</style>
